package com.wayne.testapp.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wayne.testapp.R;

import java.util.List;

/**
 * Created by wayne on 2016/06/28.
 */
public class RecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static int TYPE_NORMAL = 0;
    private static int TYPE_FOOTER = 1;

    private List<String> list;


    public void setList(List<String> list) {
        this.list = list;
    }


    public String getData(int position) {
        return list.get(position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_recycle, null);
        MainViewHolder holder1 = new MainViewHolder(view);
        return holder1;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MainViewHolder) {
            MainViewHolder holder1 = (MainViewHolder) holder;
            holder1.setData();
        }
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }


    class MainViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_str;


        public MainViewHolder(View itemView) {
            super(itemView);
            tv_str = (TextView) itemView.findViewById(R.id.tv_str);
        }

        public void setData() {
            String str = getData(getAdapterPosition());
            tv_str.setText(str);
        }
    }

    class FooterViewHolder extends RecyclerView.ViewHolder {

        public FooterViewHolder(View itemView) {
            super(itemView);
        }
    }
}
